//
//  UIButton+Extension.swift
//  sinaWeibo
//
//  Created by liii on 16/7/21.
//  Copyright © 2016年 liii. All rights reserved.
//

import UIKit

extension UIButton {
    
    // 工具条加号按钮
    class func buttonWithImage(image: String, backgroundImage: String) -> UIButton {
        let b = UIButton()
        b.setImage(UIImage(named: image), forState:.Normal)
        b.setImage(UIImage(named: image + "_highlighted"), forState:.Highlighted)
        b.setBackgroundImage(UIImage(named: backgroundImage), forState:.Normal)
        b.setBackgroundImage(UIImage(named: backgroundImage + "_highlighted"), forState:.Highlighted)
        b.sizeToFit()
        return b
    }
    
    // 登陆注册按钮
    class func buttonWithTitle(title: String, fontSize: CGFloat, color: UIColor, backgroundImage: String?, image: String? = nil) -> UIButton {
        let b = UIButton()
        b.setTitle(title, forState: .Normal)
        b.setTitleColor(color, forState: .Normal)
        if image != nil  {
            b.setImage(UIImage(named: image!), forState: .Normal)
        }
        if backgroundImage != nil {
            b.setBackgroundImage(UIImage(named: backgroundImage!), forState: .Normal)
        }
        b.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        b.sizeToFit()
        return b
    }
    
}
